#include<iostream>
using namespace std;
#include<string>
#include<stack>
class Solution {
public:
    string decodeString(string s) {
        stack<int> num;
        stack<string> str;
        str.push("");
        int n = s.size();
        for (int i = 0; i < n; ++i)
        {
            if (s[i] >= '0' && s[i] <= '9')
            {
                int now = s[i] - '0';
                while (s[i + 1] >= '0' && s[i + 1] <= '9')
                {
                    now *= 10;
                    now += s[i + 1] - '0';
                    ++i;
                }
                num.push(now);
            }
            else if (s[i] == ']')
            {
                int now = num.top();
                num.pop();
                string str1 = str.top();
                str.pop();
                while (now--)
                    str.top() += str1;
            }
            else if (s[i] == '[')
                str.push("");
            else
                str.top() += s[i];
        }
        return str.top();
    }
};
int main() {
    string str("abc3[cd]xyz");
    Solution().decodeString(str);
}